<template>
    <div class="order-report">
        <div class="report-table-top-title" style="height: 64px">
            商家信息
            <span
                style="color: red; font-size: 14px"
                v-if="managementType !== 3"
                >（新增商家在商家平台的登录账号是商家编号，密码是联系电话后六位）</span
            >
            <span style="float: right">
                <span
                    style="color: #000; font-size: 15px; margin-left: 10px"
                ></span>
                <el-button type="primary" size="small" plain @click="onSubmit"
                    >确认新增</el-button
                >
                <el-button type="danger" size="small" plain @click="toMain"
                    >返回</el-button
                >
            </span>
        </div>

        <div class="report-table-form1">
            <div class="report-table-form1-line">
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px"
                >
                    商家名称:
                </div>
                <div class="report-table-form1-item" style="width: 180px">
                    <el-input
                        v-model="companyName"
                        placeholder="必填"
                        size="small"
                    ></el-input>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px"
                >
                    支付通道:
                </div>
                <div class="report-table-form1-item" style="width: 180px">
                    <el-select
                        v-model="payChannel"
                        placeholder="请选择"
                        size="small"
                    >
                        <el-option
                            v-for="item in optionsPay"
                            v-if="item.show"
                            :key="item.key"
                            :label="item.value"
                            :value="item.key"
                        ></el-option>
                    </el-select>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 190px; color: #e21c18; font-size: 12px"
                    v-show="payChannel === 3"
                >
                    账户信息请到娱加云商家后台配置
                </div>
            </div>
            <div class="report-table-form1-line" v-show="managementType === 3">
                <!-- 商家总店 娱加云总店 -->
                <div
                    class="report-table-form1-item word samll"
                    v-show="managementType === 3"
                    style="width: 70px"
                >
                    选择总店:
                </div>
                <div
                    class="report-table-form1-item"
                    v-show="managementType === 3"
                >
                    <el-select
                        v-model="mainCompanyCode"
                        filterable
                        placeholder="请选择"
                        size="small"
                    >
                        <el-option
                            v-for="item in mainCompanyList"
                            :key="item.mainCompanyCode"
                            :label="item.mainCompanyName"
                            :value="item.mainCompanyCode"
                        ></el-option>
                    </el-select>
                    <el-button
                        type="primary"
                        size="small"
                        plain
                        @click="getDate"
                        >使用该总店信息创建分店</el-button
                    >
                </div>
            </div>
            <div class="report-table-form1-line">
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px"
                >
                    商家地址:
                </div>
                <div
                    class="report-table-form1-item"
                    style="width: 180px; margin-right: 1px"
                >
                    <el-select
                        v-model="provincialLevelCode"
                        placeholder="请选择"
                        @change="
                            cityLevelCode = '',
                            countyCode = ''
                        "
                        size="small"
                    >
                        <el-option
                            v-for="item in options1"
                            :key="item.regioncode"
                            :label="item.regionname"
                            :value="item.regioncode"
                        ></el-option>
                    </el-select>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 35px"
                >
                    省
                </div>
                <div
                    class="report-table-form1-item"
                    style="width: 180px; margin-right: 1px"
                >
                    <el-select
                        v-model="cityLevelCode"
                        placeholder="请选择"
                        @change="countyCode = ''"
                        size="small"
                    >
                        <el-option
                            v-for="item in options2"
                            :key="item.regioncode"
                            :label="item.regionname"
                            :value="item.regioncode"
                        ></el-option>
                    </el-select>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 35px"
                >
                    市
                </div>
                <div
                    class="report-table-form1-item"
                    style="width: 180px; margin-right: 1px"
                >
                    <el-select
                        v-model="countyCode"
                        placeholder="请选择"
                        size="small"
                    >
                        <el-option
                            v-for="item in options3"
                            :key="item.regioncode"
                            :label="item.regionname"
                            :value="item.regioncode"
                        ></el-option>
                    </el-select>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 35px"
                >
                    区
                </div>
            </div>
            <div class="report-table-form1-line">
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px"
                >
                    详细地址:
                </div>
                <div class="report-table-form1-item" style="width: 400px">
                    <el-input
                        v-model="address"
                        placeholder="省、市、详细地址必填"
                        size="small"
                    ></el-input>
                </div>
            </div>
            <div class="report-table-form1-line">
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px"
                >
                    联系人:
                </div>
                <div class="report-table-form1-item" style="width: 180px">
                    <el-input
                        v-model="contact"
                        placeholder="必填"
                        size="small"
                    ></el-input>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px"
                >
                    联系电话:
                </div>
                <div class="report-table-form1-item" style="width: 180px">
                    <el-input
                        v-model="telPhone"
                        placeholder="必填"
                        size="small"
                    ></el-input>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 35px"
                >
                    备注:
                </div>
                <div class="report-table-form1-item" style="width: 180px">
                    <el-input
                        v-model="remark"
                        placeholder="选填"
                        size="small"
                    ></el-input>
                </div>
            </div>
            <div class="report-table-form1-line">
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px"
                >
                    状态:
                </div>
                <div class="report-table-form1-item" style="width: 180px">
                    <el-radio v-model="status" :label="0">正常</el-radio>
                    <el-radio v-model="status" :label="1">停用</el-radio>
                </div>
            </div>
            <div class="report-table-form1-line" v-show="managementType === 2">
                <el-checkbox v-model="hasFY">锋云信息</el-checkbox>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 35px"
                ></div>
                <el-select
                    v-model="fyServerNO"
                    placeholder="请选择"
                    size="small"
                    filterable
                    default-first-option
                    :disabled="!hasFY"
                >
                    <el-option
                        v-for="item in FYList"
                        :key="item"
                        :label="item"
                        :value="item"
                    ></el-option>
                </el-select>
            </div>
            <div class="report-table-form1-line" v-if="managementType === 2">
                <span style="color: red; font-size: 14px"
                    >利云酒吧剩余软件套数：{{
                        unregistedbarsoftpackagecount
                    }}，利云酒吧软件总套数：{{ totalbarsoftpackagecount }}</span
                >
            </div>
            <!-- <div class="report-table-form1-line" v-if="managementType === 3">
                <span style="color: red; font-size: 14px"
                    >娱加云剩余软件套数：{{
                        unregistedyunbarsoftpackagecount
                    }}，娱加云软件总套数：{{
                        totalyunbarsoftpackagecount
                    }}</span
                >
            </div> -->
            <div class="report-table-form1-line" v-if="managementType === 4">
                <span style="color: red; font-size: 14px"
                    >利瑜养生剩余软件套数：{{
                        yssurplussoftwareinventory
                    }}，利瑜养生软件总套数：{{ yssoftwareinventory }}</span
                >
            </div>
            <div class="report-table-form1-line" v-if="managementType === 3">
                <div
                    class="report-table-form1-item word samll"
                    style="width: 130px"
                >
                    利云服务器序列号:
                </div>
                <div
                    class="report-table-form1-item"
                    style="width: 180px; margin-bottom: 20px"
                >
                    <el-select
                        v-model="dogNo"
                        placeholder="参考图片获取序列号"
                        filterable
                        clearable
                        size="small"
                    >
                        <el-option
                            v-for="item in dogNoList"
                            :key="item.dogNo"
                            :label="item.dogNo"
                            :value="item.dogNo"
                        ></el-option>
                    </el-select>
                </div>
                <div
                    class="tipPic2"
                    title="点击预览"
                    @click="prevViewImg(tipUrl)"
                >
                    <img class="a" :src="tipUrl" width="100%" height="100%" />
                </div>
            </div>
        </div>

        <div
            class="report-table-top-title"
            style="height: 64px"
            v-show="managementType === 2 || managementType === 4"
        >
            设备信息
            <span style="color: #000; font-size: 15px; margin-left: 20px"
                >(可稍后添加)</span
            >
            <el-button
                type="primary"
                size="small"
                v-if="!showAddDevice"
                @click="showAddDevice = !showAddDevice"
                >展开</el-button
            >
            <el-button
                type="primary"
                size="small"
                v-if="showAddDevice"
                @click="showAddDevice = !showAddDevice"
                >收起</el-button
            >
            <!-- <el-button type="danger" plain size="small" @click="showSNTip=true">SN码图片提示</el-button> -->
        </div>

        <div
            class="report-table-form1"
            v-if="
                showAddDevice && (managementType === 2 || managementType === 4)
            "
        >
            <!--<div class="report-table-form1-line">-->
            <!--<div class="report-table-form1-item word samll" style="width: 70px">-->
            <!--序列号:-->
            <!--</div>-->
            <!--<div class="report-table-form1-item" style="width: 180px">-->
            <!--<el-input v-model="searchNo" placeholder="" size="medium"></el-input>-->
            <!--</div>-->
            <!--<el-button type="primary" size="medium">搜索</el-button>-->
            <!--<div class="report-table-form1-item word samll" style="width: 50px"></div>-->
            <!--<div class="report-table-form1-item word samll" style="width: 200px">-->
            <!--已选设备：X台-->
            <!--</div>-->
            <!--</div>-->
            <div v-if="produckList.length == 0">暂无设备信息</div>
            <div v-for="(item, index) in produckList" :key="index">
                <h3 style="margin-bottom: 20px">{{ item.terminalTypeName }}</h3>
                <!-- <div
                    class="tipPic"
                    :style="{
                        background: 'url(' + item.terminalImageUrl + ')',
                    }"
                ></div> -->
                <!-- <el-image class="tipPic" :preview-src-list="[item.terminalImageUrl]" :src='item.terminalImageUrl'></el-image> -->

                <div class="tipPic2" v-show='item.terminalImageUrl'>
                    <img
                        v-show='item.terminalImageUrl'
                        class="a"
                        :src="item.terminalImageUrl"
                        width="100%"
                        height="100%"
                        @click="prevViewImg(item.terminalImageUrl)"
                    />
                </div>
                <div
                    style="width: 1000px; margin-bottom: 20px; margin-top: 20px"
                >
                    <el-transfer
                        v-model="item.selectTerminalList"
                        :data="item.terminalList"
                        filterable
                        :props="{ label: 'chipID', key: 'chipID' }"
                        :titles="['未添加', '已添加']"
                        filter-placeholder="请输入主板SN码"
                        :button-texts="['删除', '添加']"
                    ></el-transfer>
                </div>
            </div>

            <!-- <div v-show="managementType === 4">
                <div
                    class="tipPic"
                    :style="{
                        background: 'url(' + terminalImageClockUrl + ')',
                    }"
                ></div>
                <div
                    style="width: 1000px; margin-bottom: 20px; margin-top: 20px"
                >
                    <el-transfer
                        v-model="activeTerminalClock"
                        :data="terminalClockList"
                        filterable
                        :titles="['未添加', '已添加']"
                        filter-placeholder="请输入主板SN码"
                        :button-texts="['删除', '添加']"
                    ></el-transfer>
                </div>
            </div> -->
        </div>

        <!-- <div class="report-table-top-title" style="height: 64px">
            授权信息
            <span
                style="color: red;font-size: 14px"
            >（代理商剩余云管软件库存：{{unregistedsoftwarecount}}，代理商剩余云管云存储库存：{{unregisteddatainventorycount}}，</span>
            <span
                style="color: red;font-size: 14px"
            >代理商剩余酒吧软件库存：{{unregistedbarsoftwarecount}}，代理商剩余酒吧云存储库存：{{unregistedbardatainventorycount}}）</span>
        </div> -->

        <!-- <div class="report-table-form1">
            <div class="report-table-form1-line">
                <div class="report-table-form1-item word samll" style="width: 120px">包厢/卡台数量:</div>
                <div class="report-table-form1-item" style="width: 120px">
                    <el-input-number
                        size="small"
                        v-model="roomPoint"
                        controls-position="right"
                        :min="useFYMinPoint?setting.hasFyMinPoint:setting.noFyMinPoint"
                        :max="setting.maxPoint"
                    ></el-input-number>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 135px;color: red"
                >个(默认上限{{setting.maxPoint}}点)</div>
            </div>
            <div class="report-table-form1-line">
                <div class="report-table-form1-item word samll" style="width: 120px">软件使用有效期:</div>
                <div class="report-table-form1-item" style="width: 130px">
                    <el-select v-model="softwareExpiredTime" placeholder="请选择" size="small">
                        <el-option
                            v-for="item in options5"
                            :key="item.value + item.label"
                            :label="item.label"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 435px;color: red"
                >(购买2年使用10年，即注册10年仅扣除代理商双倍点数)</div>
            </div>
            <div class="report-table-form1-line" style="padding-top: 10px">
                <el-checkbox v-model="buyStore">云存储服务</el-checkbox>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 435px;color: red;line-height: 20px"
                >(未购买云存储仅保存一个月营业数据)</div>
            </div>
            <div class="report-table-form1-line">
                <div class="report-table-form1-item word samll" style="width: 150px">循环存储时长:</div>
                <div class="report-table-form1-item" style="width: 120px">
                    <el-input-number
                        :disabled="!buyStore"
                        size="small"
                        v-model="memoryCloudsLenght"
                        controls-position="right"
                        :min="1"
                        :max="1"
                    ></el-input-number>
                </div>
                <div class="report-table-form1-item word samll" style="width: 35px">年</div>
                <div class="report-table-form1-item word samll" style="width: 60px">有效期:</div>
                <div class="report-table-form1-item" style="width: 120px">
                    <el-input-number
                        :disabled="!buyStore"
                        size="small"
                        v-model="memoryCloudsExpiredTime"
                        controls-position="right"
                        :min="1"
                        :max="1"
                    ></el-input-number>
                </div>
                <div class="report-table-form1-item word samll" style="width: 35px">年</div>
            </div>
        </div> -->

        <!-- <div class="report-table-top-title" style="height: 64px">代理商点数库存扣除提示</div>

        <div class="report-table-form1">
            <div class="report-table-form1-line">
                <div class="report-table-form1-item word samll" style="width: 150px">授权后:</div>
            </div>
            <div class="report-table-form1-line">
                <div class="report-table-form1-item word samll" style="width: 150px">包厢/台卡数:</div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px;color: red"
                >{{roomPoint}}</div>
            </div>
            <div class="report-table-form1-line">
                <div class="report-table-form1-item word samll" style="width: 150px">有效期:</div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 370px;color: red"
                >{{$ND()}}至{{$NDT(softwareExpiredTime)}}</div>
            </div>
            <div class="report-table-form1-line">
                <div class="report-table-form1-item word samll" style="width: 150px">云存储:</div>
                <div class="report-table-form1-item word samll" style="width: 870px;color: red">
                    营业数据保留
                    <span v-show="buyStore">365</span>
                    <span v-show="!buyStore">30</span>
                    天
                    <span v-show="buyStore">，有效期{{$ND()}}至{{$NDT(1)}}</span>
                </div>
            </div>
            <div class="report-table-form1-line">
                <div class="report-table-form1-item word samll" style="width: 120px">软件点数扣除:</div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px;color: red;text-align:center"
                >{{roomPoint * (softwareExpiredTime===10?2:1)}}点</div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 635px"
                >（软件点数=包厢/卡台个数*软件有效期，如果选择10年则软件点数=包厢/卡台个数*2）</div>
            </div>
            <div class="report-table-form1-line">
                <div class="report-table-form1-item word samll" style="width: 120px">云存储点数扣除:</div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 70px;color: red;text-align:center"
                >{{buyStore ? roomPoint * memoryCloudsLenght * memoryCloudsExpiredTime : 0}}点</div>
                <div
                    class="report-table-form1-item word samll"
                    style="width: 535px"
                >（云存储点数=包厢/卡台个数*循环存储时长*有效期）</div>
            </div>
        </div> -->

        <el-dialog title="SN码图片提示" :visible.sync="showSNTip" width="600px">
            <div class="tipPic"></div>
            <div slot="footer" class="dialog-footer">
                <el-button
                    type="primary"
                    @click="showSNTip = false"
                    size="small"
                    >确 定</el-button
                >
            </div>
        </el-dialog>

        <!-- <el-dialog title="提示" :visible.sync="showComfire" width="30%">
            <span v-show="managementType === 1">是否确认新增KTV商家，确认后经营类型不能修改</span>
            <span v-show="managementType === 2">是否确认新增酒吧商家，确认后经营类型不能修改</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="showComfire=false">取消</el-button>
                <el-button type="primary" @click="realSubmit">确定</el-button>
            </span>
        </el-dialog> -->

        <div class="page-padding-gray-small"></div>
        <el-dialog title="图片预览" :visible.sync="prevViewImgShow" width="70%">
            <div class="prev-view-img-box">
                <img
                    class="a"
                    :src="terminalImageUrlPrevView"
                    style="max-width: 100%"
                />
            </div>
        </el-dialog>
    </div>
</template>

<script type="text/ecmascript-6">
export default {
    data: function () {
        return {
            dogNo: '',
            dogNoList: [],
            tipUrl: '',
            produckList: [
                { terminalList: [], selectTerminalList: [] }
            ],
            showSNTip: false,
            showComfire: false, // 提示新增后商家类型不可改变
            /* roomPoint: 0, */
            setting: {},
            options5: [
                {
                    label: '一年',
                    value: 1
                },
                {
                    label: '十年',
                    value: 10
                }
            ],
            /* softwareExpiredTime: 10, */
            hasFY: false,
            buyStore: true,
            /* memoryCloudsLenght: 1, // 循环存储时长
            memoryCloudsExpiredTime: 1, // 云存储有效期限 */
            FYList: [],
            fyServerNO: '',
            // 授权和加点参数分割线

            status: 0,
            companyName: '',
            /* expiredTime: '', */

            provincialLevelCode: '',
            provincialLevelName: '',
            cityLevelCode: '',
            cityLevelName: '',
            countyCode: '',
            countyName: '',

            address: '',

            contact: '',
            telPhone: '',
            remark: '',
            activeTerminalClock: [],
            terminalClockList: [],
            terminalList: [],
            terminalImageClockUrl: '',
            terminalImageUrl: '',
            prevViewImgShow: false, // 图片预览
            terminalImageUrlPrevView: '', // 图片预览目标
            activeTerminals: [],
            unregistedsoftwarecount: 0,
            unregisteddatainventorycount: 0,
            unregistedbarsoftwarecount: 0,
            unregistedbardatainventorycount: 0,

            unregistedbarsoftpackagecount: 0, // 酒吧剩余软件套数
            totalbarsoftpackagecount: 0, // 酒吧软件总套数
            unregistedyunbarsoftpackagecount: 0, // 娱加云软件 剩余套数
            totalyunbarsoftpackagecount: 0, // 娱加云软件 总套数
            yssurplussoftwareinventory: 0, // 养生
            yssoftwareinventory: 0, // 养生
            showAddDevice: false,

            searchNo: '',

            options1: [
                {
                    regionname: '省份',
                    regioncode: ''
                }
            ],

            options2: [
                {
                    regionname: '城市',
                    regioncode: ''
                }
            ],

            options3: [
                {
                    regionname: '区/县',
                    regioncode: ''
                }
            ],
            optionsPay: [
                {
                    value: '娱加',
                    show: true,
                    key: 1
                }, {
                    value: 'K米',
                    show: true,
                    key: 2
                }, {
                    value: '原生微信/支付宝',
                    show: false,
                    key: 3
                }
            ],
            optionsPay1: [
                {
                    value: '娱加',
                    show: true,
                    key: 1
                }
            ],
            options4: [
            ],
            payChannel: 1,
            mainCompanyList: [],
            mainCompanyCode: '', // 娱加云总店
            optionsPayTimer: null,
            optionsPayCount: 0
        }
    },
    mounted () {
    },
    created () {
        this.getCompanyCanUseDogNo()
        this.getImageTip()
        this.getNoUseMachine()
        this.getRest()
        this.getProvice()
        this.getSetting()
        this.getFYList()
        this.getMainCompany()
        // 小酒吧 只留下 娱加 支付
        if (this.managementType === 2) {
            this.optionsPay[2].show = false
            this.optionsPay[1].show = false
            if (this.payChannel === 3) {
                this.payChannel = 1
            }
        } else if (this.managementType === 4) {
            this.optionsPay = this.optionsPay1
        } else {
            this.optionsPay[2].show = true
        }
    },
    watch: {
        useFYMinPoint () {
            if (this.useFYMinPoint) {
                this.roomPoint = this.setting.hasFyMinPoint
            } else {
                this.roomPoint = this.setting.noFyMinPoint
            }
        },
        provincialLevelCode () {
            if (this.provincialLevelCode === '') {
                this.options2 = [
                    {
                        regionname: '城市',
                        regioncode: ''
                    }
                ]
                this.options3 = [
                    {
                        regionname: '区/县',
                        regioncode: ''
                    }
                ]
                this.cityLevelCode = ''
                this.countyCode = ''
                return
            }
            this.options1.forEach(item => {
                if (this.provincialLevelCode === item.regioncode) {
                    this.provincialLevelName = item.regionname
                }
            })
            this.getCity()
        },
        cityLevelCode () {
            if (this.cityLevelCode === '') {
                this.options3 = [
                    {
                        regionname: '区/县',
                        regioncode: ''
                    }
                ]
                this.countyCode = ''
                return
            }
            this.options2.forEach(item => {
                if (this.cityLevelCode === item.regioncode) {
                    this.cityLevelName = item.regionname
                }
            })
            this.getCounty()
        },
        countyCode () {
            this.options3.forEach(item => {
                if (this.countyCode === item.regioncode) {
                    this.countyName = item.regionname
                }
            })
        }
    },
    components: {
    },
    props: {
        underLine: null,
        managementType: Number
    },
    computed: {
        useFYMinPoint () {
            if (this.fyServerNO !== '' && this.hasFY) {
                return true
            } else {
                return false
            }
        }
    },
    methods: {
        async getDate () {
            if (!this.mainCompanyCode) {
                return this.$message.warning('请先选择总店！')
            }
            let res = await this.$http.post(this.$store.state.IP + '/system/yjyunmaincompany/getMainCompanyByCode', {
                data: {
                    mainCompanyCode: Number(this.mainCompanyCode)
                }
            })
            let response = res.data
            if (response.ret === '0') {
                this.companyName = response.data.company.mainCompanyName
                this.contact = response.data.company.relationName
                this.telPhone = response.data.company.relationPhone
                this.address = response.data.company.mainCompanyAddress

                this.provincialLevelCode = response.data.province.regioncode
                this.provincialLevelName = response.data.province.regionname

                this.cityLevelCode = response.data.country.regioncode
                this.cityLevelName = response.data.country.regionname
                this.countyCode = response.data.city.regioncode
                this.countyName = response.data.city.regionname
            }
        },
        getCompanyCanUseDogNo () {
            let params = {
            }
            this.$http
                .get(
                    this.$store.state.IP +
                    '/dogNoManage/getCompanyCanUseDogNo?agentId=' + this.$store.state.agentIdFY,
                    params
                )
                .then(
                    response => {
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            this.dogNoList = response.res
                        }
                        if (response.ret !== '0') {
                            console.log('请求结账单详情失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
        },
        getImageTip () {
            let params = {
            }
            this.$http
                .get(
                    this.$store.state.IP +
                    '/system/company/getDogNoConsultPictureUrl',
                    params
                )
                .then(
                    response => {
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            this.tipUrl = response.res
                            /* this.roomPoint = this.setting.noFyMinPoint */
                        }
                        if (response.ret !== '0') {
                            console.log('请求结账单详情失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
        },
        prevViewImg (value) {
            // 预览图片
            console.log(value)
            this.terminalImageUrlPrevView = value
            this.prevViewImgShow = true
        },
        getFYList () {
            this.$http.post(this.$store.state.IP + '/fyservice/getMarketFyserverlist', {
                data: {
                    companyid: -1
                }
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    console.log('调用锋云服务器列表成功')
                    console.log(response.data)
                    this.FYList = response.data
                }
                if (response.ret !== '0') {
                    console.log('调用锋云服务器列表失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        },
        getSetting () {
            let params = {
                params: {
                    businessType: this.managementType
                }
            }
            this.$http
                .get(
                    this.$store.state.IP +
                    '/agent/getParamerByBusinessType',
                    params
                )
                .then(
                    response => {
                        console.log(
                            '-------------------------------------------'
                        )
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            console.log('请求结账单详情成功')
                            console.log(response.data)
                            this.setting = response.data
                            /* this.roomPoint = this.setting.noFyMinPoint */
                        }
                        if (response.ret !== '0') {
                            console.log('请求结账单详情失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
        },
        getNoUseMachine () {
            let params = {
                params: {
                }
            }
            this.activeTerminals = []
            this.activeTerminalClock = []
            this.$http.post(this.$store.state.IP + '/system/company/getAllNotActiveTerminalByAgent?managementType=' + this.managementType + '', params).then(response => {
                response = response.body
                if (response.ret === '0') {
                    console.log('调用未使用设备列表成功')
                    this.produckList = response.data
                    // 处理 整机码 添加到 sn后面（整机码）
                    this.addZJM()
                    // this.terminalImageClockUrl = response.data.terminalImageClockUrl
                    // this.terminalImageUrl = response.data.terminalImageUrl

                    // response.data.terminalClockList.forEach(item => {
                    //     this.terminalClockList.push({
                    //         key: item,
                    //         label: item
                    //     })
                    // })
                    // response.data.terminalList.forEach(item => {
                    //     this.terminalList.push({
                    //         key: item,
                    //         label: item
                    //     })
                    // })
                }
                if (response.ret !== '0') {
                    console.log('调用未使用设备列表失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        },
        addZJM () {
            // 处理 整机码 添加到 sn后面（整机码）
            this.produckList.map(product => {
                if (product.terminalType !== 4 && product.terminalType !== 5 && product.terminalType !== 6) {
                    product.terminalList.map(item => {
                        let mergeStr = item.chipID + '(' + (item.chipCode || '') + ')'
                        // 已选 列表 selectTerminalList
                        for (let i = 0; i < product.selectTerminalList.length; i++) {
                            if (product.selectTerminalList[i] === item.chipID) {
                                product.selectTerminalList[i] = mergeStr
                            }
                        }
                        this.$set(item, 'chipID', mergeStr)
                    })
                }
            })
        },
        getMainCompany () {
            // 娱加云 获取 总店列表
            this.$http.post(this.$store.state.IP + '/system/yjyunmaincompany/getMainCompany', {
                data: {
                    agentID: this.$store.state.agentIdFY
                }
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                response = response.body
                if (response.ret === '0') {
                    this.mainCompanyList = response.data
                }
            })
        },
        getSellClass () {
            this.$http.post(this.$store.state.IP + '/system/company/getManagementTypeDict', {
                data: {
                }
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    console.log('调用获取经营类型列表成功')
                    console.log(response.data)
                    response.data.forEach(item => {
                        this.options4.push(item)
                    })
                }
                if (response.ret !== '0') {
                    console.log('调用获取经营类型列表失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        },
        getProvice () {
            let params = {
                params: {
                }
            }
            this.$http.get(this.$store.state.IP + '/region/provincialLevel', params).then(response => {
                console.log('-------------------------------------------')
                console.log('调用获取行政区域返回')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    console.log('调用返回行政区域成功')
                    response.data.forEach(item => {
                        this.options1.push(item)
                    })
                }
                if (response.ret !== '0') {
                    console.log('调用返回行政区域失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
            // 调用删除人员接口
        }, // 获取省份

        getCity () {
            this.$http.post(this.$store.state.IP + '/region/cityLevel', {
                data: {
                    preCode: this.provincialLevelCode
                }
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    console.log('调用获取城市列表成功')
                    console.log(response.data)
                    this.options2 = [
                        {
                            regionname: '城市',
                            regioncode: ''
                        }
                    ]
                    response.data.forEach(item => {
                        this.options2.push(item)
                    })
                }
                if (response.ret !== '0') {
                    console.log('调用获取城市列表失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        },

        getCounty () {
            this.$http.post(this.$store.state.IP + '/region/countyLevel', {
                data: {
                    preCode: this.cityLevelCode
                }
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    console.log('调用获取区/县列表成功')
                    console.log(response.data)
                    this.options3 = [
                        {
                            regionname: '区/县',
                            regioncode: ''
                        }
                    ]
                    response.data.forEach(item => {
                        this.options3.push(item)
                    })
                }
                if (response.ret !== '0') {
                    console.log('调用获取区/县列表失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        },

        showMessage (message) {
            this.$message({
                showClose: true,
                message: message,
                type: 'warning'
            })
        },
        getProduckListJson () {
            // 获取 设备信息处理
            let produckListJson = this.copyArr(this.produckList)
            produckListJson.map(product => {
                if (product.terminalType !== 4 && product.terminalType !== 5 && product.terminalType !== 6) {
                    product.terminalList = product.terminalList ? product.terminalList : []
                    product.terminalList.map(item => {
                        item.chipID = item.chipID || ''
                        let sliceIndex = item.chipID.indexOf('(')
                        item.chipID = item.chipID.slice(0, sliceIndex)
                    })
                    for (let i = 0; i < product.selectTerminalList.length; i++) {
                        product.selectTerminalList[i] = product.selectTerminalList[i] || ''
                        let sliceIndex = product.selectTerminalList[i].indexOf('(')
                        product.selectTerminalList[i] = product.selectTerminalList[i].slice(0, sliceIndex)
                    }
                }
            })
            return JSON.stringify(produckListJson)
        },
        realSubmit () {
            this.$http.post(this.$store.state.IP + '/system/company/saveOrEdit', {
                data: {
                    companyName: this.companyName,
                    managementType: this.managementType,
                    /* expiredTime: this.expiredTime, */
                    provincialLevelCode: this.provincialLevelCode,
                    provincialLevelName: this.provincialLevelName,
                    cityLevelCode: this.cityLevelCode,
                    cityLevelName: this.cityLevelName,
                    countyLevelCode: this.countyCode || this.cityLevelCode,
                    countyLevelName: this.countyCode ? this.countyName : this.cityLevelName,
                    address: this.address,
                    contact: this.contact,
                    dogNo: this.dogNo,
                    telPhone: this.telPhone,
                    remark: this.remark,
                    activeTerminals: this.getProduckListJson(),
                    status: this.status,
                    fyServerNO: this.hasFY ? this.fyServerNO : '',
                    /* softwareExpiredTime: this.softwareExpiredTime, */
                    /* roomPoint: this.roomPoint, */
                    /* memoryCloudsLenght: this.memoryCloudsLenght,
                    memoryCloudsExpiredTime: this.memoryCloudsExpiredTime, */
                    state: this.buyStore ? 1 : 0,
                    longitude: '',
                    latitude: '',
                    netPayChannel: this.payChannel,
                    mainCompanyCode: this.mainCompanyCode,
                    isSpareChannel: 1 // 0是 1否 网络支付是否走备用通道
                }
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    this.showMessage('添加商家成功')
                    this.toMain()
                    console.log('添加商家成功')
                }
            }, response => {
                console.log('通讯失败')
            })
        },
        onSubmit () {
            let message = ''
            if (this.telPhone === '') {
                message = '请输入联系方式'
            }
            if (this.contact === '') {
                message = '请输入联系人'
            }
            if (this.address === '') {
                message = '请输入详细地址'
            }
            // if (this.countyCode === '') {
            //     message = '请选择区县'
            // }
            if (this.cityLevelCode === '') {
                message = '请选择城市'
            }
            if (this.provincialLevelCode === '') {
                message = '请选择省份'
            }
            // if (this.expiredTime === '') {
            //     message = '请选择过期时间'
            // }
            if (this.managementType === '') {
                message = '请选择经营类型'
            }
            if (this.companyName === '') {
                message = '请输入商家名称'
            }
            if (message !== '') {
                this.showMessage(message)
                return
            }
            // this.showComfire = true
            this.realSubmit()
        },

        toMain () {
            this.dogNo = ''
            this.companyName = ''
            /* this.expiredTime = '' */
            this.provincialLevelCode = ''
            this.provincialLevelName = ''
            this.cityLevelCode = ''
            this.cityLevelName =
                this.countyCode = ''
            this.countyName = ''
            this.address = ''
            this.contact = ''
            this.telPhone = ''
            this.remark = ''
            this.activeTerminals = []
            this.activeTerminalClock = []
            this.fyServerNO = ''
            /* this.softwareExpiredTime = 1 */
            /* this.roomPoint = 1 */
            /* this.memoryCloudsLenght = 1
            this.memoryCloudsExpiredTime = 1 */
            this.$store.dispatch('setKA', 0)
        },

        getRest () {
            this.$http.post(this.$store.state.IP + '/system/stock/getStockByAgent', {
                data: {
                }
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    console.log('获取库存详情成功')
                    console.log(response.data)
                    this.unregistedsoftwarecount = response.data.unregistedsoftwarecount
                    this.unregisteddatainventorycount = response.data.unregisteddatainventorycount
                    this.unregistedbarsoftwarecount = response.data.unregistedbarsoftwarecount
                    this.unregistedbardatainventorycount = response.data.unregistedbardatainventorycount
                    this.unregistedbarsoftpackagecount = response.data.unregistedbarsoftpackagecount
                    this.totalbarsoftpackagecount = response.data.totalbarsoftpackagecount
                    this.totalyunbarsoftpackagecount = response.data.totalyunbarsoftpackagecount
                    this.unregistedyunbarsoftpackagecount = response.data.unregistedyunbarsoftpackagecount
                    this.yssoftwareinventory = response.data.yssoftwareinventory
                    this.yssurplussoftwareinventory = response.data.yssurplussoftwareinventory
                }
                if (response.ret !== '0') {
                    console.log('获取库存详情失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
.tipPic2
    width: 560px
    height: 200px
    // background: url('../../../../../common/pic/addDevicePic.png')
    background-repeat: no-repeat
    background-size: 100% 100%
    cursor: pointer

.prev-view-img-box
    text-align: center

.el-transfer-panel
    width: 400px

.order-report
    width: 100%
    background: #f1f0f5

    .report-table-top-title
        width: 100%
        height: 64px
        line-height: 64px
        color: #000
        font-size: 18px

    .report-table-form1
        width: 100%
        min-height: 40px
        padding: 16px 0 0 22px
        box-sizing: border-box
        background: #fff
        overflow: hidden

        .report-table-form1-line
            min-height: 32px
            margin-bottom: 16px

            .report-table-form1-item
                display: inline-block
                vertical-align: top
                height: 32px
                margin-right: 15px
                line-height: 32px

                &.word
                    margin-right: 0

                &.samll
                    font-size: 15px
                    text-align: left

                &.big
                    margin-right: 100px

    .report-table-block
        width: 100%
        padding-top: 22px
        height: 50px
        background: #fff
        box-sizing: border-box

        .report-table-block-in
            float: right
            padding-right: 17px

    .page-padding-gray-small
        width: 100%
        height: 22px
        background: #f1f0f5

    .page-padding
        width: 100%
        height: 20px
        background: #fff

    .report-table-total
        width: 100%
        font-size: 16px
        color: #409EFF
        padding: 22px
        margin-top: 22px
        box-sizing: border-box
        background: #fff
</style>
